// pages/enterprise/user/setting-edit/email/email.js
import {isInputEmpty, isEmail} from "../../../../utils/Util"
import Behavior from "../behavior";
Component({
    /*
    * 组件间代码共享
    * */
    behaviors: [Behavior],

    /**
     * 组件的属性列表
     */
    properties: {
        value: {
            type: String,
            value: ""
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        _email: "",
        _emailErrorMsg: ""
    },

    observers: {
        "value": function (val) {
            if (val) {
                this.data._email = val
            }
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {

        /*
        * 点击保存按钮
        * */
        onSaveButton: function () {
            let email = this.data._email;
            let isLoading = this.data.isLoading;
            if (isLoading) { //防重复
                return false
            } else if (!isInputEmpty(email)) {
                this.setData({_emailErrorMsg: "邮箱不能为空"})
                return false
            } else if (!isEmail(email)) {
                this.setData({_emailErrorMsg: "邮箱格式不正确"})
                return false
            } else {
                this.triggerEvent("save", {email: email});
            }
        }
    }
})

